<template>
  <div>
    <router-link tag="div" to="/" class="header-abs">
      <i class="iconfont icon-fanhui"></i>
    </router-link>
    <div class="header-fix" :style="opacityStyle">
      <router-link to="/">
      <div class="header-left">
        <i class="iconfont icon-fanhui"></i>
      </div>
    </router-link>
    <div class="header-title">
      <span>景点门票</span>
    </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      console.log('123')
      let scrollDistance = document.documentElement.scrollTop ||
                           document.body.scrollTop || window.pageYOffset // 考虑到兼容性
      if (scrollDistance > 55) {
        let opacity = scrollDistance / 200
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = {opacity}
      } else {
        this.opacityStyle = {opacity: 0}
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang='stylus' rel='stylesheet/stylus' scoped>
  .header-abs
    position absolute
    left .3rem
    top .3rem
    width .8rem
    height .8rem
    line-height .8rem
    border-radius .4rem
    text-align center
    background rgba(0, 0, 0, .6)
    .iconfont
      color #fff
   @import '~styles/varibles.styl'
  .header-fix
    position fixed
    top 0
    left 0
    right 0
    overflow hidden
    height $headerHeight
    line-height $headerHeight
    color #fff
    font-size .32rem
    background $bgColor
    .header-left
      float left
      width .8rem
      text-align center
      color #fff
      .iconfont
        font-size .3rem
    .header-title
      text-align center
      span
        position relative
        left -.4rem
</style>
